package com.basic.modules.nykf.controller;

import com.basic.common.annotation.StringTrim;
import com.basic.common.utils.PageUtils;
import com.basic.common.utils.ParamsModel;
import com.basic.common.utils.R;
import com.basic.modules.nykf.entity.RenewListEntity;
import com.basic.modules.nykf.entity.RenewShouEntity;
import com.basic.modules.nykf.entity.RenewTuiEntity;
import com.basic.modules.nykf.service.RenewManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 续费管理
 * 开始时间：2025-04-14
 */
@RestController
@RequestMapping("new/ykf/renewManage")
public class RenewManageController {

    @Autowired
    RenewManageService renewManageService;

    /**
     * 获取续费记录
     *
     * @param params
     * @return
     */
    @StringTrim
    @PostMapping("/getRenewManageList")
    public R getRenewManageList(@RequestBody ParamsModel<RenewListEntity> params) {
        PageUtils page = renewManageService.getRenewManageList(params);
        return R.ok(page);
    }

    /**
     * 根据批次ID获取收款记录
     *
     * @param renewShouEntity
     * @return
     */
    @PostMapping("/getRenewShouList")
    public R getRenewShouList(@RequestBody RenewShouEntity renewShouEntity) {
        return renewManageService.getRenewShouList(renewShouEntity);
    }

    /**
     * 根据批次ID获取退款记录
     *
     * @param renewTuiEntity
     * @return
     */

    @PostMapping("/getRenewTuiList")
    public R getRenewTuiList(@RequestBody RenewTuiEntity renewTuiEntity) {
        return renewManageService.getRenewTuiList(renewTuiEntity);
    }

    /**
     * 提交支付信息
     *
     * @param map
     * @return
     */
    @PostMapping("/postSkList")
    public R postSkList(@RequestBody Map map) {
        List<RenewShouEntity> renewShouEntities = (List<RenewShouEntity>) map.get("skList");
        // 收费模式(分组)
        String sfmsVal = map.get("sfmsVal").toString();
        // 客户ID
        Long customerId = Long.parseLong(map.get("customerId").toString());
        // 续费日期
        String xfrq = map.get("xfrq").toString();
        // 批次ID
        String batchId = null;
        if (map.get("batchId") != null) {
            batchId = map.get("batchId").toString();
        } else {
            batchId = UUID.randomUUID().toString().replace("-", "");
        }
        Long customerShopBusinessId = Long.parseLong(map.get("customerShopBusinessId").toString());
        renewManageService.postSkList(renewShouEntities, customerId, sfmsVal, batchId, customerShopBusinessId, xfrq);
        return R.ok();
    }

    /**
     * 提交退款信息
     *
     * @param map
     * @return
     */

    @PostMapping("/postTkList")
    public R postTkList(@RequestBody Map map) {
        List<RenewTuiEntity> renewTuiEntities = (List<RenewTuiEntity>) map.get("tkList");
        // 收费模式(分组)
        String sfmsVal = map.get("sfmsVal").toString();
        // 客户ID
        Long customerId = Long.parseLong(map.get("customerId").toString());
        // 批次ID
        String batchId = map.get("batchId").toString();
        Long customerShopBusinessId = Long.parseLong(map.get("customerShopBusinessId").toString());
        renewManageService.postTkList(renewTuiEntities, customerId, sfmsVal, batchId, customerShopBusinessId);
        return R.ok();
    }

    /**
     * 提交续费信息
     *
     * @param map
     * @return
     */
    @PostMapping("/postXfList")
    public R postXfList(@RequestBody Map map) {
        return renewManageService.postXfList(map);
    }

    /**
     * 根据收费模式及客户ID查询业务数据
     *
     * @param renewListEntity
     * @return
     */
    @PostMapping("/getXfywListBySfmsValAndCustomerId")
    public R getXfywListBySfmsValAndCustomerId(@RequestBody RenewListEntity renewListEntity) {
        return renewManageService.getXfywListBySfmsValAndCustomerId(renewListEntity);
    }
}